<?php
/*!
 * LostKids PHP Library v0.1 
 * http://huali.li/
 *
 * Copyright 2011, 
 * Written By James Pang
 *  
 * Date: 2011/2/14
 */

require_once (dirname(__FILE__).'/../configs.php');

$msgSrcAdaptor = Assembly::getService('MsgSrcAdaptor', true);
$register = Assembly::getService('Register', true);
$policies = Assembly::getService('UserPolicies', true);

// TODO process those hunging msgs

$msgs = $msgSrcAdaptor->retrieveMsgs();

foreach ($msgs as $msg) {
    try{
        switch ( $msg->getMsgType() ) {
        case WeiboMessage::TYPE_SEEK:
            if(!$policies->registerFaceSeeker($msg, true))
                break;
        case WeiboMessage::TYPE_REPORT:
            $register->registerFaces($msg);
            break;
        case WeiboMessage::TYPE_NON_MATCH:
            $register->registerUser($msg);
            break;
        case WeiboMessage::TYPE_MATCH:
            $register->matchFaces($msg);
            break;
        case WeiboMessage::TYPE_CONFIRM:
            $register->confirmFound($msg);
            break;
        default:
            throw new BizException('invalid msg type, msgId='.$msg->id);
            break;
        }
    }catch(BizException $e) {
        // TODO
    }catch(Exception $e) {
        error_log('Error processing a msg in cron, lid='.$msg->id.$e);// TODO $e.toString
    }
}
?>
